from django.db import models
from django.core.validators import RegexValidator
# Create your models here.

class DailyTask(models.Model):
    create_date = models.DateField(verbose_name='日期',unique=True)
    text_data = models.TextField(verbose_name='任务分配文本')


    class Meta:
        verbose_name = "任务分配"
        verbose_name_plural = verbose_name

    def __str__(self):
        return f"{self.create_date}"
    

class MemberPeople(models.Model):
    name_data = models.CharField(verbose_name='姓名',max_length=5)
    phone_number = models.CharField(
        verbose_name='联系方式',
        max_length=11,
        validators=[
            RegexValidator(
                r'^1[3-9]\d{9}$',
                message='请输入正确的11位手机号码'
            )
        ],
        unique=True
    )


    class Meta:
        verbose_name = "实施人员"
        verbose_name_plural = verbose_name

    def __str__(self):
        return f"{self.name_data}"
    
    def to_dict(self):
        return {"name": self.name_data, "phone_number": self.phone_number}